package com.situ.mall.common.mapper;

import com.situ.mall.common.entity.Cart;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.situ.mall.common.vo.CartVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author lwj
 * @since 2023-09-23
 */
public interface CartMapper extends BaseMapper<Cart> {
    @Select("select * from cart where product_id =#{pId} and member_id = #{mId}")
    Cart selectByPId(@Param("pId") Integer pId, @Param("mId") Integer mId);



    @Select("select product.id, product.title,product.price,product.taste,product.packages,product.img_path,cart.amount from cart inner join product on cart.product_id = product.id where  member_id = #{mId}")
    List<CartVO> select(Integer mId);

    @Delete("delete from cart where product_id = #{pId} and member_id = #{mId}")
    void deleteOne(Integer pId,Integer mId);

    @Update("update cart set amount = #{newAmount} where product_id = #{pId} and member_id = #{mId}")
    void addOne(Integer pId, Integer mId,Integer newAmount);

    @Update("update cart set amount = #{newAmount} where product_id = #{pId} and member_id = #{mId}")
    void reduceOne(Integer pId, Integer mId,Integer newAmount);

    @Select("select product.id, product.title,product.price,product.taste,product.packages,product.img_path,cart.amount from cart inner join product on cart.product_id = product.id where member_id = #{mId} and product_id = #{cId}")
    List<CartVO> select2(Integer mId, Integer cId);

    @Select("select * from cart where product_id =#{pid} and member_id=#{mid} ")
    Cart selectByproductid(@Param("pid") Integer i,@Param("mid") Integer mid);

    @Select("select product.id, product.title,product.price,product.taste,product.packages,product.img_path,cart.amount from cart inner join product on cart.product_id = product.id where member_id = #{mId} and product_id = #{cid}")
    CartVO select1(Integer mId, Integer cid);
}
